//package Servlet1;
//
//import dao.UserDao;
//import model.User;
//
//import javax.servlet.ServletException;
//import javax.servlet.annotation.WebServlet;
//import javax.servlet.http.HttpServlet;
//import javax.servlet.http.HttpServletRequest;
//import javax.servlet.http.HttpServletResponse;
//import java.io.IOException;
//
//@WebServlet(urlPatterns = "/ModifyUser2.do")
//public class modifyUser extends HttpServlet {
//    private UserDao userDao;
//
//    public modifyUser() {
//        this.userDao = new UserDao();
//    }
//
//
//    @Override
//    protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
//        String userIdParam = req.getParameter("id");
//        if (userIdParam == null || userIdParam.isEmpty()) {
//            resp.sendError(HttpServletResponse.SC_BAD_REQUEST, "User ID is required");
//            return;
//        }
//
//        try {
//            int userId = Integer.parseInt(userIdParam);
//            User user = userDao.getUserById(userId);
//
//            if (user != null) {
//                req.setAttribute("user", user);
//                req.getRequestDispatcher("/admin/modifyUser.jsp").forward(req, resp);
//            } else {
//                resp.sendError(HttpServletResponse.SC_NOT_FOUND, "User not found");
//            }
//        } catch (NumberFormatException e) {
//            resp.sendError(HttpServletResponse.SC_BAD_REQUEST, "Invalid User ID format");
//        }
//    }
//
//
//    @Override
//    protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
//        req.setCharacterEncoding("UTF-8");
//
//        String userIdParam = req.getParameter("id");
//        if (userIdParam == null || userIdParam.isEmpty()) {
//            resp.sendError(HttpServletResponse.SC_BAD_REQUEST, "User ID is required");
//            return;
//        }
//
//        try {
//            int userId = Integer.parseInt(userIdParam);
//            String username = req.getParameter("username");
//            String gender = req.getParameter("gender");
//            String profession = req.getParameter("profession");
//            String favor = req.getParameter("favor");
//            String description = req.getParameter("description");
//            int state = Integer.parseInt(req.getParameter("state"));
//            int role = Integer.parseInt(req.getParameter("role"));
//
//            User user = new User();
//            user.setId(userId);
//            user.setUsername(username);
//            user.setGender(gender);
//            user.setProfession(profession);
//            user.setFavorString(favor);
//            user.setDescription(description);
//            user.setState(state);
//            user.setRole(role);
//
//            boolean isUpdated = userDao.updateUser(user);
////
//            if (isUpdated) {
//                resp.sendRedirect(req.getContextPath() + "/userList.do");
//            } else {
//                resp.sendError(HttpServletResponse.SC_INTERNAL_SERVER_ERROR, "User update failed");
//            }
//        } catch (NumberFormatException e) {
//            resp.sendError(HttpServletResponse.SC_BAD_REQUEST, "Invalid input format");
//        }
//    }
//}
